
package com.lsw.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.lsw.R;
import com.lsw.util.DensityUtil;
import com.lsw.util.LogUtils;
import com.lsw.util.ToastUtil;


/**
 * 无网络状态
 *
 * @author lsw
 */
public class NoHttpDialogProgress extends Dialog {

    public NoHttpDialogProgress(Context context, View.OnClickListener onfinshListener, View.OnClickListener onLoadListener) {
        super(context, R.style.DialogProgress);
        this.onfinshListener = onfinshListener;
        this.onLoadListener = onLoadListener;
    }

    TextView tv_load;
    ImageView iv_finsh;
    View.OnClickListener onfinshListener, onLoadListener;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.nohttp_dialog_progress);

        Window windowDia = this.getWindow();
        WindowManager.LayoutParams lp = windowDia.getAttributes();
        lp.gravity = Gravity.BOTTOM;
        windowDia.setAttributes(lp);
        int height = DensityUtil.getScreenHeight(getContext()) - DensityUtil.getStatusBarHeight(getContext());
        LogUtils.i("lsw", "height==" + height);
        windowDia.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, height);
        setCanceledOnTouchOutside(false);
        tv_load = findViewById(R.id.tv_load);
        iv_finsh = findViewById(R.id.iv_finsh);
        iv_finsh.setOnClickListener(onfinshListener);
        tv_load.setOnClickListener(onLoadListener);
        setOnKeyListener(keylistener);
    }

    DialogInterface.OnKeyListener keylistener = new DialogInterface.OnKeyListener() {
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
                //do something...
                if (onfinshListener != null)
                    onfinshListener.onClick(iv_finsh);
                return false;
            } else {
                return true;
            }
        }
    };

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
    }
}
